﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _3_5
{
    public partial class Form1 : Form
    {
        private CountDistance countDistance = new CountDistance();

        public Form1()
        {
            InitializeComponent();
            this.Text = "里程计算";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                double currentDistance = double.Parse(textBox1.Text);
                countDistance.Distance = currentDistance;
                countDistance.CalculateTotal();
                MessageBox.Show($"您的汽车已经行驶 {CountDistance.TotalDistance} 公里", "里程结果");
            }
            catch (FormatException)
            {
                MessageBox.Show("请输入有效的公里数！", "输入错误");
            }
        }
    }
}
namespace _3_5
{
    public class CountDistance
    {
        private double distance;  
        private static double totalDistance;  

        
        public double Distance
        {
            get { return distance; }
            set { distance = value; }
        }

        
        public static double TotalDistance
        {
            get { return totalDistance; }
            set { totalDistance = value; }
        }

      
        public void CalculateTotal()
        {
            TotalDistance += Distance;
        }
    }
}